package com.thoughtworks;

import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        //
        System.out.println("Easiest exercise ever:");
        System.out.println("*");
        //
        System.out.println("Draw a horizontal line:");
        if (sc.hasNext()) {
            int inputNumber = sc.nextInt();
            while (inputNumber-- > 0) {
                System.out.print("*");
            }
        }
        System.out.println("");
        //
        System.out.println("Draw a vertical line");
        if (sc.hasNext()) {
            int inputNumber = sc.nextInt();
            while (inputNumber-- > 0) {
                System.out.println("*");
            }
        }
        //
        System.out.println("Draw a right triangle");
        if (sc.hasNext()) {
            final int inputNumber = sc.nextInt();
            for (int line = 0; line < inputNumber; ++line) {
                for (int i = 0; i < line + 1; ++i) {
                    System.out.print("*");
                }
                System.out.println("");
            }
        }
        //
        System.out.println("Isosceles Triangle:");
        if (sc.hasNext()) {
            final int inputNumber = sc.nextInt();
            for (int line = 0; line < inputNumber; ++line) {
                for (int i = 0; i < inputNumber - line - 1; ++i) {
                    System.out.print(" ");
                }
                for (int i = 0; i < 2 * line + 1; ++i) {
                    System.out.print("*");
                }
                System.out.println("");
            }
        }
        //
        System.out.println("Diamond:");
        if (sc.hasNext()) {
            final int inputNumber = sc.nextInt();
            for (int line = 0; line < inputNumber; ++line) {
                for (int i = 0; i < inputNumber - line - 1; ++i) {
                    System.out.print(" ");
                }
                for (int i = 0; i < 2 * line + 1; ++i) {
                    System.out.print("*");
                }
                System.out.println("");
            }
            for (int line = inputNumber - 2; line > -1; --line) {
                for (int i = 0; i < inputNumber - line - 1; ++i) {
                    System.out.print(" ");
                }
                for (int i = 0; i < 2 * line + 1; ++i) {
                    System.out.print("*");
                }
                System.out.println("");
            }
        }
        //
        System.out.println("Diamond with Name:");
        if (sc.hasNext()) {
            final int inputNumber = sc.nextInt();
            for (int line = 0; line < inputNumber-1; ++line) {
                for (int i = 0; i < inputNumber - line - 1; ++i) {
                    System.out.print(" ");
                }
                for (int i = 0; i < 2 * line + 1; ++i) {
                    System.out.print("*");
                }
                System.out.println("");
            }
            System.out.println("CyningMi");
            for (int line = inputNumber - 2; line > -1; --line) {
                for (int i = 0; i < inputNumber - line - 1; ++i) {
                    System.out.print(" ");
                }
                for (int i = 0; i < 2 * line + 1; ++i) {
                    System.out.print("*");
                }
                System.out.println("");
            }
        }
        //
        System.out.println("FizzBuzz:");
        for(int i=0;i<=100;++i)
        {
            if(i%3 == 0)
                System.out.print("Fizz");
            if(i%5 == 0)
                System.out.print("Buzz");
            if(i%3 != 0 && i%5 != 0)
                System.out.print(i);
            System.out.println("");
        }
        //
        System.out.println("Prime Factors Exercise:");
        if (sc.hasNext()) {
            final int inputNumber = sc.nextInt();
            generate(inputNumber).forEach(System.out::println);//java-8
        }
    }

    private static Set<Integer> generate(int inputNumber) {
        Set<Integer> factors = new HashSet<>();
        int limit = (int) Math.sqrt(inputNumber) + 2;//careful the "5.99999", etc
        outer:
        for(int i=2;i<limit;++i)
            if(inputNumber%i==0) {
                for (int temp : factors)//recurse is a better way
                    if(i%temp==0)
                        break outer;
                factors.add(i);
            }
        return factors;
    }
}